package evq.codec.ui;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;

import evq.codec.core.converters.Converter;
import evq.codec.core.entities.Dictionary;
import evq.codec.core.entities.Pgm;
import evq.codec.core.entities.Profiler;
import evq.codec.core.entities.Vector;
import evq.codec.core.managers.impl.DefaultFileManager;
import evq.codec.ui.util.ImageUtil;
import evq.codec.ui.util.JImagePanel;

/**
 * @author Gutemberg Rodrigues
 * @author Edson Jordão
 */
public class ResultFrame extends javax.swing.JFrame {

	private Profiler profiler;
	private double rate;
	private double mse;
	private double psnr;
	private DefaultFileManager fileManager;
	private Dictionary dictionary;
	private Pgm pgmDecoded;
	private String pathImageCodec;
	Map<Integer, JImagePanel> blocos;
	ImageUtil imageUtil = new ImageUtil();
	private JImagePanel actualImageDicPanel;

	public ResultFrame() {
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}

	public ResultFrame(Profiler profile, double rate, double mse, double psnr,
			String pathImageOriginal, String pathImageCodec,
			String pathDictionary) {
		this.pathImageCodec = pathImageCodec;
		this.fileManager = DefaultFileManager.getInstance();
		this.dictionary = fileManager.loadDictionaryFile(pathDictionary);
		this.pgmDecoded = fileManager.loadPgmFile(this.pathImageCodec);
		try {
			initComponents(pathImageOriginal, pathImageCodec, dictionary);
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Erro",
					JOptionPane.ERROR_MESSAGE);
		}
		this.profiler = profile;
		this.rate = rate;
		this.mse = mse;
		this.psnr = psnr;
		loadValues();
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}

	@SuppressWarnings("unchecked")
	private void initComponents(String pathImageOriginal,
			String pathImageCodec, Dictionary dictionary) throws IOException {

		// lógica para inicializar n blocos do dicionário
		blocos = new HashMap<Integer, JImagePanel>();
		for (int i = 0; i < dictionary.getSize(); i++) {
			blocos.put((Integer) dictionary.getCodes().toArray()[i],
					new JImagePanel(imageUtil.dicToJpg(dictionary.getVector(i),
							dictionary.getQuantizatorDimension()), 0, 0));
		}

		BufferedImage original = imageUtil.pgmToJpg(pathImageOriginal);
		BufferedImage decoded = imageUtil.pgmToJpg(pathImageCodec);
		panelImageOriginal = new JImagePanel(original, 0, 0);
		panelImageQuantification = new JImagePanel(decoded, 0, 0);
		labelImageOrignal = new javax.swing.JLabel();
		labelImageQuant = new javax.swing.JLabel();
		painelDictionary = new javax.swing.JPanel();
		txtCostQuantification = new javax.swing.JTextField();
		txtMse = new javax.swing.JTextField();
		txtPsnr = new javax.swing.JTextField();
		labelCostQuantification = new javax.swing.JLabel();
		labelMse = new javax.swing.JLabel();
		labelPsnr = new javax.swing.JLabel();
		painelOP = new javax.swing.JPanel();
		txtMulti = new javax.swing.JTextField();
		txtDiv = new javax.swing.JTextField();
		txtComp = new javax.swing.JTextField();
		txtSub = new javax.swing.JTextField();
		txtSum = new javax.swing.JTextField();
		labelSum = new javax.swing.JLabel();
		labelSub = new javax.swing.JLabel();
		labelMulti = new javax.swing.JLabel();
		labelDiv = new javax.swing.JLabel();
		labelComp = new javax.swing.JLabel();
		txtMouse = new javax.swing.JTextField();
		labelPsnr1 = new javax.swing.JLabel();
		txtTimeExecution = new javax.swing.JTextField();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		panelImageOriginal.setBorder(javax.swing.BorderFactory
				.createLineBorder(new java.awt.Color(153, 153, 153)));
		panelImageOriginal.setPreferredSize(new java.awt.Dimension(256, 256));

		javax.swing.GroupLayout panelImageOriginalLayout = new javax.swing.GroupLayout(
				panelImageOriginal);
		panelImageOriginal.setLayout(panelImageOriginalLayout);
		panelImageOriginalLayout.setHorizontalGroup(panelImageOriginalLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 254, Short.MAX_VALUE));
		panelImageOriginalLayout.setVerticalGroup(panelImageOriginalLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGap(0, 254, Short.MAX_VALUE));

		panelImageQuantification.setBorder(javax.swing.BorderFactory
				.createLineBorder(new java.awt.Color(153, 153, 153)));
		panelImageQuantification.setPreferredSize(new java.awt.Dimension(256,
				256));
		panelImageQuantification
				.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
					public void mouseMoved(java.awt.event.MouseEvent evt) {
						panelImageQuantificationMouseMoved(evt);
					}
				});

		javax.swing.GroupLayout panelImageQuantificationLayout = new javax.swing.GroupLayout(
				panelImageQuantification);
		panelImageQuantification.setLayout(panelImageQuantificationLayout);
		panelImageQuantificationLayout
				.setHorizontalGroup(panelImageQuantificationLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGap(0, 254, Short.MAX_VALUE));
		panelImageQuantificationLayout
				.setVerticalGroup(panelImageQuantificationLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGap(0, 254, Short.MAX_VALUE));

		labelImageOrignal.setForeground(new java.awt.Color(153, 153, 153));
		labelImageOrignal.setText("Imagem Original");

		labelImageQuant.setForeground(new java.awt.Color(153, 153, 153));
		labelImageQuant.setText("Imagem Quantificada");

		painelDictionary.setBorder(javax.swing.BorderFactory
				.createTitledBorder(javax.swing.BorderFactory
						.createLineBorder(new java.awt.Color(153, 153, 153)),
						"Blocos do Dicionário\n",
						javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
						javax.swing.border.TitledBorder.DEFAULT_POSITION,
						new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(
								153, 153, 153))); // NOI18N
		painelDictionary.setAutoscrolls(true);
		
		// logica para personalizar os blocos
		for (JImagePanel bloco : blocos.values()) {
			bloco.setBorder(javax.swing.BorderFactory
					.createLineBorder(new java.awt.Color(102, 102, 102)));
			bloco.setForeground(new java.awt.Color(153, 153, 153));
			bloco.setPreferredSize(new java.awt.Dimension(16, 16));

			javax.swing.GroupLayout bloc1Layout = new javax.swing.GroupLayout(
					bloco);
			bloco.setLayout(bloc1Layout);
			bloc1Layout.setHorizontalGroup(bloc1Layout.createParallelGroup(
					javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 14,
					Short.MAX_VALUE));
			bloc1Layout.setVerticalGroup(bloc1Layout.createParallelGroup(
					javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 14,
					Short.MAX_VALUE));
		}

		javax.swing.GroupLayout painelDictionaryLayout = new javax.swing.GroupLayout(
				painelDictionary);
		painelDictionary.setLayout(painelDictionaryLayout);

		ParallelGroup parallelGroup = painelDictionaryLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);
		SequentialGroup sequentialGroup = painelDictionaryLayout
				.createSequentialGroup().addContainerGap().addPreferredGap(
						javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				.addContainerGap(843, Short.MAX_VALUE);

		// logica para adicionar as imagens(panel) dos blocos na horizontal
		for (JImagePanel bloco : blocos.values()) {
			sequentialGroup.addComponent(bloco,
					javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE);
		}
		//No 40 abaixo se aumentar o valor aumenta o painel, antes estava 78
		painelDictionaryLayout.setHorizontalGroup(parallelGroup
				.addGroup(sequentialGroup));
		
		ParallelGroup parallelGroup2 = painelDictionaryLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);
		SequentialGroup sequentialGroup2 = painelDictionaryLayout
				.createSequentialGroup().addContainerGap(40, Short.MAX_VALUE);
		ParallelGroup parallelGroup3 = painelDictionaryLayout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);

		// logica para adicionar as imagens(panel) dos blocos na vertical
		for (JImagePanel bloco : blocos.values()) {

			parallelGroup3.addComponent(bloco,
					javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE);
		}

		painelDictionaryLayout.setVerticalGroup(parallelGroup2
				.addGroup(sequentialGroup2.addGroup(parallelGroup3)));

		txtCostQuantification.setEditable(false);

		txtMse.setEditable(false);

		txtPsnr.setEditable(false);

		labelCostQuantification
				.setForeground(new java.awt.Color(102, 102, 102));
		labelCostQuantification.setText("Taxa de Quantificação:");

		labelMse.setForeground(new java.awt.Color(102, 102, 102));
		labelMse.setText("MSE:");

		labelPsnr.setForeground(new java.awt.Color(102, 102, 102));
		labelPsnr.setText("PSNR:");

		painelOP.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
				"Quantidade de Operações:",
				javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
				javax.swing.border.TitledBorder.DEFAULT_POSITION,
				new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(102,
						102, 102))); // NOI18N

		txtMulti.setEditable(false);
		txtMulti.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				txtMultiActionPerformed(evt);
			}
		});

		txtDiv.setEditable(false);

		txtComp.setEditable(false);

		txtSub.setEditable(false);

		txtSum.setEditable(false);

		labelSum.setForeground(new java.awt.Color(102, 102, 102));
		labelSum.setText("Soma:");

		labelSub.setForeground(new java.awt.Color(102, 102, 102));
		labelSub.setText("Subtração:");

		labelMulti.setForeground(new java.awt.Color(102, 102, 102));
		labelMulti.setText("Multiplicação:");

		labelDiv.setForeground(new java.awt.Color(102, 102, 102));
		labelDiv.setText("Divisão:");

		labelComp.setForeground(new java.awt.Color(102, 102, 102));
		labelComp.setText("Comparação:");

		javax.swing.GroupLayout painelOPLayout = new javax.swing.GroupLayout(
				painelOP);
		painelOP.setLayout(painelOPLayout);
		painelOPLayout
				.setHorizontalGroup(painelOPLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								painelOPLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												painelOPLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addComponent(labelSum)
														.addComponent(
																labelMulti)
														.addComponent(labelDiv)
														.addComponent(labelComp)
														.addComponent(labelSub))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
										.addGroup(
												painelOPLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(
																txtComp,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																164,
																Short.MAX_VALUE)
														.addComponent(
																txtDiv,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																164,
																Short.MAX_VALUE)
														.addComponent(
																txtMulti,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																164,
																Short.MAX_VALUE)
														.addComponent(
																txtSub,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																164,
																Short.MAX_VALUE)
														.addComponent(
																txtSum,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																164,
																Short.MAX_VALUE))
										.addContainerGap()));
		painelOPLayout
				.setVerticalGroup(painelOPLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								painelOPLayout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												painelOPLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																txtSum,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(labelSum))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												painelOPLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																txtSub,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(labelSub))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												painelOPLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																txtMulti,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																labelMulti))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												painelOPLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																txtDiv,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(labelDiv))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												painelOPLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																txtComp,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(labelComp))
										.addContainerGap(
												javax.swing.GroupLayout.DEFAULT_SIZE,
												Short.MAX_VALUE)));

		txtMouse.setEditable(false);
		txtMouse.setForeground(new java.awt.Color(102, 102, 102));

		labelPsnr1.setForeground(new java.awt.Color(102, 102, 102));
		labelPsnr1.setText("Tempo de Execução:");

		txtTimeExecution.setEditable(false);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				111,
																				111,
																				111)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								labelCostQuantification)
																						.addComponent(
																								labelMse)
																						.addComponent(
																								labelPsnr)
																						.addComponent(
																								labelPsnr1))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								false)
																						.addComponent(
																								txtTimeExecution,
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								txtPsnr)
																						.addComponent(
																								txtCostQuantification,
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								txtMse,
																								javax.swing.GroupLayout.Alignment.LEADING,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								162,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addGap(
																				75,
																				75,
																				75)
																		.addComponent(
																				painelOP,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								painelDictionary,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								layout
																										.createSequentialGroup()
																										.addGroup(
																												layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.TRAILING,
																																false)
																														.addGroup(
																																layout
																																		.createSequentialGroup()
																																		.addGap(
																																				119,
																																				119,
																																				119)
																																		.addComponent(
																																				panelImageOriginal,
																																				javax.swing.GroupLayout.PREFERRED_SIZE,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				javax.swing.GroupLayout.PREFERRED_SIZE)
																																		.addGap(
																																				153,
																																				153,
																																				153)
																																		.addComponent(
																																				panelImageQuantification,
																																				javax.swing.GroupLayout.PREFERRED_SIZE,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				javax.swing.GroupLayout.PREFERRED_SIZE))
																														.addGroup(
																																javax.swing.GroupLayout.Alignment.LEADING,
																																layout
																																		.createSequentialGroup()
																																		.addGap(
																																				200,
																																				200,
																																				200)
																																		.addComponent(
																																				labelImageOrignal)
																																		.addPreferredGap(
																																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				Short.MAX_VALUE)
																																		.addComponent(
																																				labelImageQuant)
																																		.addGap(
																																				69,
																																				69,
																																				69)))
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(
																												txtMouse,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												111,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))))
										.addContainerGap()));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								labelImageOrignal)
																						.addComponent(
																								labelImageQuant))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								panelImageOriginal,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								panelImageQuantification,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)))
														.addComponent(
																txtMouse,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addGap(18, 18, 18)
										.addComponent(
												painelDictionary,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				29,
																				29,
																				29)
																		.addComponent(
																				painelOP,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addGap(
																				32,
																				32,
																				32))
														.addGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																layout
																		.createSequentialGroup()
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																				71,
																				Short.MAX_VALUE)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								txtTimeExecution,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								labelPsnr1))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								txtCostQuantification,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								labelCostQuantification))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								txtMse,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								labelMse))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								txtPsnr,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								labelPsnr))
																		.addGap(
																				65,
																				65,
																				65)))));

		pack();
	}

	private void txtMultiActionPerformed(java.awt.event.ActionEvent evt) {
	}

	private void panelImageQuantificationMouseMoved(
			java.awt.event.MouseEvent evt) {
		txtMouse.setText("X: " + String.valueOf(evt.getPoint().getX())
				+ "    Y: " + String.valueOf(evt.getPoint().getY()));
		Pgm pgm = fileManager.loadPgmFile(this.pathImageCodec);
		int blockNumber = imageUtil
				.getBlock((int) evt.getPoint().getX(), (int) evt.getPoint()
						.getY(), this.dictionary.getQuantizatorDimension(),
						pgm.getHeight());
		List<Vector> vectors = Converter.convertPgmToVectors(pgm,
				this.dictionary.getQuantizatorDimension());
		Vector block = vectors.get(blockNumber - 1);
		int code = getDicCodeByPgmBlock(block);
		if(actualImageDicPanel != null){
			actualImageDicPanel.setBorder(null);
		}
		blocos.get(code).setBorder(BorderFactory.createLineBorder(Color.RED));
		actualImageDicPanel = blocos.get(code);
	}

	private int getDicCodeByPgmBlock(Vector block) {
		List<Integer> blockList = new ArrayList<Integer>();

		for (Iterator iterator = block.iterator(); iterator.hasNext();) {
			blockList.add(((Double) iterator.next()).intValue());

		}
		for (int i = 0; i < this.dictionary.getSize(); i++) {
			List<Integer> dicList = new ArrayList<Integer>();
			for (Iterator iterator = this.dictionary.getVector(i).iterator(); iterator
					.hasNext();) {
				dicList.add(((Long) Math.round((Double) iterator.next()))
						.intValue());
			}
			if (dicList.equals(blockList)) {
				return i;
			}
		}
		return -1;
	}

	private void loadValues() {
		txtMse.setText(String.valueOf(mse));
		txtPsnr.setText(String.valueOf(psnr));
		txtCostQuantification.setText(String.valueOf(rate));
		txtTimeExecution.setText(String.valueOf(profiler.getExecutionTime()));
		txtSum.setText(String.valueOf(profiler.getSumOperationQuantity()));
		txtSub.setText(String.valueOf(profiler.getSubtractOperationQuantity()));
		txtMulti.setText(String.valueOf(profiler
				.getMultiplicationOperationQuantity()));
		txtDiv.setText(String.valueOf(profiler.getDivisionOperationQuantity()));
		txtComp.setText(String.valueOf(profiler
				.getComparisonOperationQuantity()));

	}

	public void openResultFrame() {
		ResultFrame resultFrame = new ResultFrame();
		resultFrame.setVisible(true);
	}

	private javax.swing.JLabel labelComp;
	private javax.swing.JLabel labelCostQuantification;
	private javax.swing.JLabel labelDiv;
	private javax.swing.JLabel labelImageOrignal;
	private javax.swing.JLabel labelImageQuant;
	private javax.swing.JLabel labelMse;
	private javax.swing.JLabel labelMulti;
	private javax.swing.JLabel labelPsnr;
	private javax.swing.JLabel labelPsnr1;
	private javax.swing.JLabel labelSub;
	private javax.swing.JLabel labelSum;
	private javax.swing.JPanel painelDictionary;
	private javax.swing.JPanel painelOP;
	private JImagePanel panelImageOriginal;
	private JImagePanel panelImageQuantification;
	private javax.swing.JTextField txtComp;
	private javax.swing.JTextField txtCostQuantification;
	private javax.swing.JTextField txtDiv;
	private javax.swing.JTextField txtMouse;
	private javax.swing.JTextField txtMse;
	private javax.swing.JTextField txtMulti;
	private javax.swing.JTextField txtPsnr;
	private javax.swing.JTextField txtSub;
	private javax.swing.JTextField txtSum;
	private javax.swing.JTextField txtTimeExecution;
}
